//
//  UIViewControllerExtension.swift
//  Jock
//
//  Created by HD on 15/3/14.
//  Copyright (c) 2015年 Haidy. All rights reserved.
//

import UIKit

extension UIViewController {
    
    // navigation的高度
    var navigationHeight: CGFloat {
        get {
            let navHeight = self.navigationController?.navigationBar.frame.height
            let staHeight = UIApplication.sharedApplication().statusBarFrame.height
            return navHeight! + staHeight
        }
    }
    
    // 创建tableView的现实区域
    func createTableFrame(height: CGFloat) -> CGRect {
        var top: CGFloat = 0
        var tempHeight = height
        top += navigationHeight
        tempHeight -= navigationHeight
        return CGRectMake(0, top, UIScreen.mainScreen().bounds.width, tempHeight)
    }
    
    // 创建一个GCRect来适配7.0与8.0
    func createFrame(top: CGFloat, height: CGFloat) -> CGRect {
        return createFrame(0, top: top, width: view.frame.width, height: height)
    }
    
    // 创建一个在屏幕中间的CGRect
    func createFrame(top: CGFloat,CenterInScreenWidth width: CGFloat, height: CGFloat) -> CGRect {
        return createFrame((UIScreen.mainScreen().bounds.width - width) / 2, top: top, width: width, height: height)
    }
    
    // 创建一个GCRect来适配7.0与8.0
    func createFrame(left: CGFloat, top: CGFloat, width: CGFloat, height: CGFloat) -> CGRect {
        return CGRectMake(left, top + navigationHeight, width, height)
    }
    
}
